<template>
  <div class="home" id="form1">
    <el-container>
      <el-header
        style="
          left: 0px;
          top: 0px;
          width: 100%;
          right: 0;
          z-index: 5;
          margin-top: 0;
        "
      >
        <el-form
         
          inline="true"
          label-width="120px"
          class="formStyle"
          size="mini"
        >
       
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-tickets"
              @click="confirmData(0)"
              >保存</el-button
            >
          </el-form-item>


           <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-tickets"
              @click="printDesign(0)"
              >设计</el-button
            >
          </el-form-item>


           <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-tickets"
              @click="prn3_preview(0)"
              >打印</el-button
            >
          </el-form-item>
         
        
           <el-form-item style="height:5px">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-check"
              @click="handleClose()"
              >关闭</el-button
            >
          </el-form-item>

         
        </el-form>
      </el-header>

      <el-main style="margin: 3px 10px 10px 10px">
        <span
          style="
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            display: inline-block;
            width: 100%;
            padding: 3px 0 5px 0;
          "
        >
          <span>打印模板</span>
         
        </span>

        <el-form
          ref="form"
          :model="form"
          rules="rules"
          inline="true"
          label-width="120px"
          class="formStyle"
          size="mini"
        >
          <el-form-item label="单据编号：" >
            <el-input 
                v-model="form.TempleteId"
                placeholder="单据编号：" disabled:true
              ></el-input>
          </el-form-item>

        

         
         
            <el-form-item label="模板名称" prop="templeteName">
              <el-input
                v-model="form.templeteName"
                placeholder="请输入模板名称"
              ></el-input>
            </el-form-item>
       
            <el-form-item label="纸张高度" prop="pageHeight">
              <el-input
                v-model="form.pageHeight"
                placeholder="请输入纸张高度(单位：in(英寸)、cm(厘米)、mm(毫米)、pt(磅)、px(1/96英寸))"
              ></el-input>
            </el-form-item>
       
            <el-form-item label="纸张宽度" prop="pageWidth">
              <el-input
                v-model="form.pageWidth"
                placeholder="请输入纸张宽度(单位：in(英寸)、cm(厘米)、mm(毫米)、pt(磅)、px(1/96英寸))"
              ></el-input>
            </el-form-item>
        
            <el-form-item label="套打行数" prop="pageSize">
              <el-input
                type="number"
                v-model="form.pageSize"
                placeholder="请输入套打行数"
              ></el-input>
            </el-form-item>
       
            <el-form-item label="行高" prop="heightLine">
              <el-input
                type="number"
                v-model="form.heightLine"
                placeholder=""
              ></el-input>
            </el-form-item>


            
        </el-form>
        <el-form>
           <el-form-item label="头部" prop="head">
          <el-input
            v-model="form.head"
            :rows="10"
            type="textarea"
          ></el-input>
        </el-form-item>


        <el-form-item label="子表" prop="childTable">
          <el-input
            v-model="form.childTable"
            :rows="10"
            type="textarea"
          ></el-input>
        </el-form-item>


        <el-form-item label="尾部" prop="tail">
          <el-input
            v-model="form.tail"
            :rows="10"
            type="textarea"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="父表" prop="parentTable">
          <el-input
            v-model="form.parentTable"
            :rows="10"
            type="textarea"
          ></el-input>
        </el-form-item> -->

        </el-form>
      </el-main>
    </el-container>
  </div>
</template>

<style scoped>
.home {
  height: 100%;
}

.customWidth {
  width: 80%;
  height: 300px;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 150px;
}
.el-table .warning-row {
  background: oldlace;
}

.svg-icon[data-v-c8a70580] {
  width: 2.5em;
  height: 2.5em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
  margin-bottom: -15px;
}
</style>

<script>
import path from "path";
import { deepClone } from "@/utils";
import { templeteDesign,GetPrintDate } from "@/api/Print";
import {getDataList,updatetempleteForm} from "@/api/System";
import { getLodop } from "@/api/LodopFuncs";

export default {
  name: "editTemplete",
  components: {
  },
 computed: {
    routesData() {
      return this.routes;
    },
  },
  props: {
    inputName: String,
    required: true,
  },
  data() {
    return {
      form: [],
      formDetail:[],
       PrintDetail:[],
      dialogTableVisible: false,
      dialogFormVisible: false,
      where: "",
      rules: {
        UserName: [
          { required: true, message: "请输入推荐人称", trigger: "blur" }
        ],
       
      },
      reverse: true,
    };
  },
  created: function () {
    this.DataListData();
  },
  methods: {
    async DataListData() {
      // 提交数据，需要修改

      if (this.inputName == null) {
        this.inputName = this.$route.query.billID;
      }

      const result = await updatetempleteForm({
        billID: this.inputName,
        IsPostBack: false,
      });

      this.form = result.data.Table[0];
      this.formDetail = result.data2.Table;
      this.PrintDetail=result.data3.Table;

 

      if (result.code === 20000) {
      } else {
        this.$notify({
          title: "error",

          message: result.message,
          type: "error",
        });
      }

     
    },
    async confirmData(submit) {
      // 提交数据，需要修改

      const Fresult = true;
      

     if(this.form.head!=""&&this.form.head!=null)
     {
       this.formDetail= await GetPrintDate(1,this.formDetail,this.form.head,this.form.TempleteId);
     }

      if(this.form.childTable!=""&&this.form.childTable!=null)
     {
        this.formDetail= await GetPrintDate(2,this.formDetail,this.form.childTable,this.form.TempleteId);
     }

     if(this.form.tail!=""&&this.form.tail!=null)
     {
       this.formDetail= await GetPrintDate(3,this.formDetail,this.form.tail,this.form.TempleteId);
     }
    //this.formDetail= await GetPrintDate(2,this.formDetail,this.form.parentTable,this.form.TempleteId);


     

     
  


   

      if (Fresult) {
        const result = await updatetempleteForm({
          BillDate: JSON.stringify(this.form),
          BodyDate: JSON.stringify(this.formDetail),
          billID: this.form.TempleteId,
          IsPostBack: true,
          submit: submit,
        });
    
        this.form = result.data.Table[0];
        this.formDetail = result.data2.Table;

        this.PrintDetail=result.data3.Table;
        if (result.code === 20000) {
          
        
          this.dialogVisible = false;
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "success",
          });
         
    
        } else {
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "error",
          });
        }
      }
    }, handleClose()
    {
       this.$store.dispatch('tagsView/delView', this.$route)
// 返回上一步路由
      this.$router.go(-1)
 
    },
    //打印预览
    printPreview() {
      var LODOP=null;
      this.CreateOneFormPage(this.form);
      templeteDesign(LODOP, this.PrintDetail);
      LODOP.PREVIEW();
    },
    //打印设计
    printDesign() {
      var LODOP=null;
      LODOP = getLodop();
      LODOP.SET_PRINT_PAGESIZE(0, this.form.pageHeight, this.form.pageWidth, ""); //设定纸张大小
      LODOP.PRINT_INIT(this.form.templeteName);
      templeteDesign(LODOP, this.PrintDetail);
      LODOP.PRINT_DESIGN();
    },
    CreateOneFormPage(dataForm) {
     
      LODOP = getLodop();
      LODOP.SET_PRINT_PAGESIZE(0, dataForm.pageHeight, dataForm.pageWidth, ""); //设定纸张大小
      LODOP.PRINT_INIT(dataForm.templeteName);
    },

   prn3_preview() {
        var LODOP=null;
      LODOP = getLodop();
      LODOP.SET_PRINT_PAGESIZE(0, this.form.pageHeight, this.form.pageWidth, ""); //设定纸张大小
      LODOP.PRINT_INIT(this.form.templeteName);
      templeteDesign(LODOP, this.PrintDetail);
      LODOP.PREVIEW();
    }
  },
};
</script>

<style scoped lang='scss'>

</style>


